package com.huawei.esdk.uc.sametime.uccallbackimpl;

import org.apache.log4j.Logger;
import org.eclipse.swt.widgets.Display;

import com.huawei.esdk.uc.jna.callback.ConfMemberEventCB;
import com.huawei.esdk.uc.jna.struct.STConfParam;
import com.huawei.esdk.uc.jna.util.StringUtil;
import com.huawei.esdk.uc.sametime.widgets.EsdkUCConvWindow;

public class UCConfMemEventCallBackImpl implements ConfMemberEventCB
{

    private Logger logger = Logger.getLogger(UCConfMemEventCallBackImpl.class);

    private static UCConfMemEventCallBackImpl instance = new UCConfMemEventCallBackImpl();

    public static UCConfMemEventCallBackImpl getInstance()
    {
        return instance;
    }

    private UCConfMemEventCallBackImpl()
    {

    }

    @Override
    public void callBack(final STConfParam arg0)
    {
        String ucAccount = StringUtil.bytesToString(arg0.ucAcc);

        logger.debug("ucAccount = " + ucAccount + ", memStatus = "
                + arg0.memStatus + ", memType = " + arg0.memType);
        if (!StringUtil.isEmptyStr(ucAccount))
        {
            UpdateCallInfoJob updateJob = new UpdateCallInfoJob(arg0);
            Display.getDefault().syncExec(updateJob);
        }

    }

    private static class UpdateCallInfoJob implements Runnable
    {
        private STConfParam confParam;

        public UpdateCallInfoJob(STConfParam confParam)
        {
            this.confParam = confParam;
        }

        @Override
        public void run()
        {
            EsdkUCConvWindow.getInstance().callStart();
            EsdkUCConvWindow.getInstance().updateMembersInConf(this.confParam);
        }
    }
}
